package com.base.common.utils;

import com.alibaba.fastjson.JSONObject;
import com.base.common.entity.User;

import javax.servlet.http.HttpServletRequest;

public class UserUtils {

    /**
     * 解析请求对象的token得到用户信息
     * @param request
     * @return
     */
    public static User getUser(HttpServletRequest request) {

        // 解析请求头中的token
        String userStr = request.getHeader("user");
        User user = null;
        if(userStr != null && userStr != "") {
            user = JSONObject.parseObject(userStr, User.class);
        }
        return user;
    }
}
